import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet (name = "TestServlet", value = "/test")
    public class TestServlet implements HttpServlet, HttpServlet.TestServlet {
        @Override
        public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            ServletContext servletContext = request.getServletContext();
            WebApplicationContext spring = WebApplicationContextUtils.getWebApplicationContext(servletContext);
            System.out.println(spring.getBean("user"));
        }
    }
